package com.example.utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

import java.util.Collections;

/**
 * @Author 王鹤蒲
 * @Date 2023 07 31
 */
public class CodeGenerator {
    public static void main(String[] args) {
           generate();
    }

    private static void generate(){
        FastAutoGenerator.create("jdbc:mysql://rm-cn-5yd3d6ih8000i0po.rwlb.rds.aliyuncs.com:3306/management-system?useUnicode=true&characterEncoding=UTF-8", "root", "abcABC123")
                .globalConfig(builder -> {
                    builder.author("王鹤蒲") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .enableSwagger()
                            .outputDir("D:\\IdeaProjects\\management-system\\src\\main\\java\\"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.example") // 设置父包名
                            .moduleName(null) // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D:\\IdeaProjects\\management-system\\src\\main\\resources\\mapper\\")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.entityBuilder().enableLombok();
                    builder.mapperBuilder().enableMapperAnnotation().build();
                    builder.controllerBuilder().enableHyphenStyle().enableRestStyle();
                    builder.addInclude("sys_operation_log") // 设置需要生成的表名
                            .addTablePrefix("sys_"); // 设置过滤表前缀
                })
                .templateEngine(new VelocityTemplateEngine())
                .templateConfig(builder -> {
                    builder.entity("/templates/entity.java.vm").service("/templates/service.java.vm").serviceImpl("/templates/serviceImpl.java.vm").controller("/templates/controller.java.vm");
                })
                .execute();
    }
}
